/**
 * 个人信息页面
 */
import 'package:cbec_app/components/base/base_image.dart';
import 'package:cbec_app/components/base/base_interactive.dart';
import 'package:cbec_app/components/base/base_page.dart';
import 'package:cbec_app/components/base/base_nav_bar.dart';
import 'package:cbec_app/components/common/common_style.dart';
import 'package:cbec_app/pages/my/controller/user_info_ctr.dart';
import 'package:cbec_app/routes/routes.dart';
import 'package:cbec_app/utils/Tools.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:wechat_assets_picker/wechat_assets_picker.dart';
import 'package:wechat_camera_picker/wechat_camera_picker.dart';
import '../../../components/common/text_arrow_item.dart';

class UserInfo extends GetView<UserInfoController> {
  UserInfo({super.key});

  final TextStyle _titleStyle = const TextStyle(fontSize: 15.0, color: Color.fromRGBO(153, 153, 153, 1), fontWeight: FontWeight.w300);

  @override
  Widget build(BuildContext context) {
    return GetBuilder<UserInfoController>(builder: (controller) {
      return BasePage(
        title: "个人信息",
        iconType: IconType.back,
        children: [
          Container(
            padding: EdgeInsets.only(top: 1.w),
            color: const Color.fromRGBO(243, 245, 247, 1),
            child: Column(
              children: [
                // Container(
                //   padding: EdgeInsets.only(left: 15.w,right: 15.w),
                //   child: Row(
                //     mainAxisAlignment: MainAxisAlignment.spaceBetween,
                //     children: [
                //       Text("头像"),
                //       Row(
                //         children: [
                //           controller.headImage!.isNotEmpty?
                //           Container(
                //             width: 25.w,
                //             height: 25.w,
                //             clipBehavior: Clip.hardEdge,
                //             decoration: border_radis(Colors.white,radiusValue: 15.w),
                //             child: AssetEntityImage(controller.headImage![0],fit: BoxFit.cover),
                //           ):
                //           BaseImage(url:controller.avatar==''? "https://bolezhicai.com/assets/img/avatar.png":controller.avatar , width: 25.w,height: 25.w,borderRadius: BorderRadius.circular(55.w/2)),
                //           const Icon(
                //             Icons.arrow_forward_ios,
                //             size: 14,
                //             color: Color.fromRGBO(0, 0, 0, 0.30),
                //             weight: 700,
                //           )
                //         ],
                //       )
                //     ],
                //   ),
                // ),
                ListItem(
                    texts: "头像",
                    ohterWidget: controller.headImage!.isNotEmpty
                        ? Container(
                            width: 25.w,
                            height: 25.w,
                            clipBehavior: Clip.hardEdge,
                            decoration: border_radis(Colors.white, radiusValue: 55.w / 2),
                            child: AssetEntityImage(controller.headImage![0], fit: BoxFit.fill),
                          )
                        : BaseImage(url: controller.avatar == '' ? "default_avatar.png" : controller.avatar, width: 25.w, height: 25.w, borderRadius: BorderRadius.circular(55.w / 2)),
                    ontap: () {
                      showModalBottomSheet(
                        backgroundColor: Colors.transparent,
                        context: context,
                        builder: (BuildContext context) {
                          return Container(
                            padding: EdgeInsets.only(left: 8.w, right: 8.w),
                            height: 180.h,
                            child: Column(
                              children: <Widget>[
                                BaseInteractive(
                                    onClick: () async {
                                      final AssetEntity? entity = await CameraPicker.pickFromCamera(context);
                                      controller.headImage!.add(entity!);
                                      controller.saveImage();
                                    },
                                    childWidget: Container(
                                        decoration: const BoxDecoration(
                                            color: Colors.white,
                                            borderRadius: BorderRadius.only(
                                              topLeft: Radius.circular(20.0),
                                              topRight: Radius.circular(20.0),
                                            )),
                                        alignment: Alignment.center,
                                        width: double.infinity,
                                        height: 50.h,
                                        child: Text("拍照", style: TextStyle(fontSize: 15, fontWeight: FontWeight.w700, color: Tools.fromHex("#4D87FF"))))),
                                BaseInteractive(
                                    onClick: () async => {
                                          controller.headImage = await AssetPicker.pickAssets(
                                            context,
                                            pickerConfig: const AssetPickerConfig(maxAssets: 1),
                                          ),
                                          if (controller.headImage!.isNotEmpty)
                                            {
                                              controller.saveImage(),
                                            }
                                        },
                                    childWidget: Container(
                                        decoration: BoxDecoration(
                                          color: Colors.white,
                                          borderRadius: const BorderRadius.only(
                                            bottomLeft: Radius.circular(20.0),
                                            bottomRight: Radius.circular(20.0),
                                          ),
                                          border: Border(
                                            top: BorderSide(
                                              color: Tools.fromHex("#D7D7D7"),
                                              width: 1.0,
                                            ),
                                          ),
                                        ),
                                        alignment: Alignment.center,
                                        width: double.infinity,
                                        height: 50.h,
                                        child: Text("从相册选择", style: TextStyle(fontSize: 15, fontWeight: FontWeight.w700, color: Tools.fromHex("#4D87FF"))))),
                                BaseInteractive(onClick: () => {Get.back()}, childWidget: Container(decoration: border_radis(Colors.white, radiusValue: 20), margin: EdgeInsets.only(top: 10.w), alignment: Alignment.center, width: double.infinity, height: 50.h, child: Text("取消", style: TextStyle(fontSize: 15, fontWeight: FontWeight.w700, color: Tools.fromHex("#4D87FF"))))),
                              ],
                            ),
                          );
                        },
                      );
                    }),

                ListItem(
                    texts: "昵称",
                    ohterWidget: Text(
                      controller.nickname,
                      style: _titleStyle,
                    ),
                    ontap: () => {
                          Tools.showInputModal(
                            title: "修改昵称",
                            placeholder: "请输入新昵称",
                            onInput: (value) {
                              controller.nickname = value;
                            },
                            onConfirm: (tag) {
                              controller.updateName(tag);
                            },
                          )
                        }),
                ListItem(
                    texts: "手机号",
                    ohterWidget: Text(
                      controller.phoneNumber,
                      style: _titleStyle,
                    ),
                    ontap: () => {Get.toNamed(Routes.fixPhone)}),
              ],
            ),
          ),
        ],
      );
    });
  }
}
